package com.example.websocketdemo.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.websocketdemo.config.WebSocketTest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/monitoring")
public class MonitoringAlarmController {

    @GetMapping("/message")
    public void m(HttpServletResponse response) throws IOException {
        response.setHeader("Access-Control-Allow-Origin", "*");
//        JSONObject jsonObject = new JSONObject();
//        JSONObject json = new JSONObject();
//        JSONObject xinxi = new JSONObject();
//        JSONObject xinxi1 = new JSONObject();
//        JSONObject xinxi2 = new JSONObject();
//
//        JSONArray Array = new JSONArray();
//        jsonObject.put("instruction","updatepoi");
//        json.put("updatetype","reset");
//        json.put("poigroup","baojing");
//        json.put("poitype","baojing");
//
//        xinxi.put("报警状态","手动终止");
//        xinxi.put("位号","LYG_5450_PT_01001_PV");
//        xinxi.put("报警级别","低报");
//        xinxi.put("报警类型","重大危险源报警");
//        xinxi.put("描述","重芳烃罐●001/高/低报警");
//        xinxi.put("读值","0.063");
//        xinxi.put("h","8");
//        xinxi.put("hh","");
//        xinxi.put("I","0.1");
//        xinxi.put("II","");
//        xinxi.put("阈值上限","8");
//        xinxi.put("阈值下限","0.1");
//        xinxi.put("量程上限","15");
//        xinxi.put("量程下限","-15");
//        xinxi.put("计量单位","Kpa");
//        xinxi.put("报警时间","2022-02-23 15:42:00");
//        xinxi.put("报警结束时间","2022-02-23 16:24:53");
//        xinxi.put("指标编码","2");
//        xinxi.put("设备编码","5450-TK-001");
//        xinxi.put("指标名称","");
//        xinxi.put("指标类型","压力");
//        xinxi.put("X","-5678");
//        xinxi.put("Y","1234");
//
//
//        xinxi1.put("报警状态","手动终止");
//        xinxi1.put("位号","LYG_5450_TT_01002_PV");
//        xinxi1.put("报警级别","低报");
//        xinxi1.put("报警类型","重大危险源报警");
//        xinxi1.put("描述","重芳烃罐●002/高/低报警");
//        xinxi1.put("读值","19.885");
//        xinxi1.put("h","50");
//        xinxi1.put("hh","");
//        xinxi1.put("I","20");
//        xinxi1.put("II","");
//        xinxi1.put("阈值上限","50");
//        xinxi1.put("阈值下限","20");
//        xinxi1.put("量程上限","100");
//        xinxi1.put("量程下限","0");
//        xinxi1.put("计量单位","℃");
//        xinxi1.put("报警时间","2022-02-22 05:54:00");
//        xinxi1.put("报警结束时间","2022-02-22 05:57:34");
//        xinxi1.put("指标编码","");
//        xinxi1.put("设备编码","5450-TK-002");
//        xinxi1.put("指标名称","");
//        xinxi1.put("指标类型","");
//        xinxi1.put("X","-4678");
//        xinxi1.put("Y","678");
//
//        xinxi2.put("报警状态","手动终止");
//        xinxi2.put("位号","LYG_5450_TT_01002_PV");
//        xinxi2.put("报警级别","低报");
//        xinxi2.put("报警类型","重大危险源报警");
//        xinxi2.put("描述","重芳烃罐●002/高/低报警");
//        xinxi2.put("读值","19.91");
//        xinxi2.put("h","50");
//        xinxi2.put("hh","");
//        xinxi2.put("I","20");
//        xinxi2.put("II","");
//        xinxi2.put("阈值上限","50");
//        xinxi2.put("阈值下限","20");
//        xinxi2.put("量程上限","100");
//        xinxi2.put("量程下限","0");
//        xinxi2.put("计量单位","℃");
//        xinxi2.put("报警时间","2022-02-22 04:54:00");
//        xinxi2.put("报警结束时间","2022-02-22 05:52:02");
//        xinxi2.put("指标编码","");
//        xinxi2.put("设备编码","5450-TK-002");
//        xinxi2.put("指标名称","");
//        xinxi2.put("指标类型","");
//        xinxi2.put("X","-7986");
//        xinxi2.put("Y","123");
//
//        Array.add(xinxi);
//        Array.add(xinxi1);
//        Array.add(xinxi2);
//        json.put("Array",Array);
//        jsonObject.put("param",json);
////        WebSocketTest.sendInfo(jsonObject.toJSONString(), "connect");
        JSONObject jsonObject_one = new JSONObject();
        jsonObject_one.put("instruction","resetpoi");
        WebSocketTest.sendInfo(jsonObject_one.toJSONString(), "connect");

        JSONObject jsonObject2 = new JSONObject();
        JSONObject json2 = new JSONObject();
        jsonObject2.put("instruction","showpoi");
        json2.put("showtype","group");
        json2.put("poigroup","jiancebaojing");
        json2.put("poitype","jiancebaojing");
        jsonObject2.put("param",json2);
        WebSocketTest.sendInfo(jsonObject2.toJSONString(), "connect");

//        for (int i = 0; i < 2; i++) {
//            if (i == 0) {
//                WebSocketTest.sendInfo(jsonObject.toJSONString(), "connect");
//            } else {
//                WebSocketTest.sendInfo(jsonObject2.toJSONString(), "connect");
//            }
//        }
    }
}
